﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DColor = System.Drawing.Color;
using MColor = System.Windows.Media.Color;

namespace NJT.扩展
{
    public static class 颜色扩展
    {
        /// <summary>
        /// Converts a System.Windows.Media.Color to a System.Drawing.Color.
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static DColor ToDColor(this MColor c)
        {
            return DColor.FromArgb(c.A, c.R, c.G, c.B);
        }

        /// <summary>
        /// Converts a System.Drawing.Color to a System.Windows.Media.Color.
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static MColor ToMColor(this DColor c)
        {
            return MColor.FromArgb(c.A, c.R, c.G, c.B);
        }

        /// <summary>
        /// Converts a byte array of three bytes to a System.Windows.Media.Color.
        /// </summary>
        /// <param name="c"></param>
        /// <param name="btColor"></param>
        /// <returns></returns>
        public static MColor FromBytes(this MColor c, byte[] btColor)
        {
            if (btColor == null || btColor.Length != 3)
                throw new ArgumentException("Invalid array size for incoming color.", "btColor");
            return MColor.FromRgb(btColor[0], btColor[1], btColor[2]);
        }

        /// <summary>
        /// Converts a byte array of three bytes to a System.Drawing.Color.
        /// </summary>
        /// <param name="c"></param>
        /// <param name="btColor"></param>
        /// <returns></returns>
        public static DColor FromBytes(this DColor c, byte[] btColor)
        {
            if (btColor == null || btColor.Length != 3)
                throw new ArgumentException("Invalid array size for incoming color.", "btColor");
            return DColor.FromArgb(255, btColor[0], btColor[1], btColor[2]);
        }

        /// <summary>
        /// Converts a System.Windows.Media.Color to a three byte array.
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static byte[] ToBytes(this MColor c)
        {
            return new byte[] { c.R, c.G, c.B };
        }

        /// <summary>
        /// Converts a System.Drawing.Color to a three byte array.
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static byte[] ToBytes(this DColor c)
        {
            return new byte[] { c.R, c.G, c.B };
        }
    }
}
